package com.tsoj.model.vo;

import cn.hutool.core.date.DateTime;
import cn.hutool.json.JSONUtil;

import com.tsoj.model.codesandbox.JudgeInfo;
import com.tsoj.model.po.QuestionSubmit;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;

@Data
public class QuestionSubmitVO implements Serializable {
    //id
    private Long id;
    //编程语言
    private String language;
    //用户代码
    private String code;
    //判题信息
    private JudgeInfo judgeinfo;
    /**
     * 判题状态（0 - 待判题、1 - 判题中、2 - 成功、3 - 失败）
     */
    private Integer status;

    /**
     * 题目 id
     */
    private Long questionid;

    /**
     * 创建用户 id
     */
    private Long userid;

    /**
     * 创建时间
     */
    private DateTime createtime;

    /**
     * 更新时间
     */
    private DateTime updatetime;

    /**
     * 提交用户信息
     */
    private UserVO userVO;

    /**
     * 对应题目信息
     */
    private QuestionVO questionVO;



    /**
     * 包装类转对象
     */
    public QuestionSubmit voToObj(QuestionSubmitVO questionSubmitVO) {
        if(questionSubmitVO == null){
            return null;
        }
        QuestionSubmit questionSubmit = new QuestionSubmit();
        BeanUtils.copyProperties(questionSubmitVO,questionSubmit);
        JudgeInfo judgeInfoObj = questionSubmitVO.getJudgeinfo();
        if(judgeInfoObj != null){
            questionSubmit.setJudgeinfo(JSONUtil.toJsonStr(judgeInfoObj));
        }
        return questionSubmit;
    }
    /**
     * 对象转包装类
     */
    public static QuestionSubmitVO objToVo(QuestionSubmit questionSubmit) {
        if(questionSubmit == null){
            return null;
        }
        QuestionSubmitVO questionSubmitVO = new QuestionSubmitVO();
        BeanUtils.copyProperties(questionSubmit,questionSubmitVO);
        String judgeInfoStr = questionSubmit.getJudgeinfo();
        questionSubmitVO.setJudgeinfo(JSONUtil.toBean(judgeInfoStr, JudgeInfo.class));
        return questionSubmitVO;
    }
    private static final long serialVersionUID = 1L;
}
